<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "{{%painting}}".
 *
 * @property integer $id
 * @property integer $category_id
 * @property integer $user_id
 * @property string $image
 * @property string $thumb
 * @property string $title
 * @property string $describe
 * @property integer $status
 * @property integer $show_banner
 * @property integer $created_at
 * @property integer $updated_at
 */
class Painting extends \yii\db\ActiveRecord
{
    /**
     * show_banner 显示状态
     */
    const IS_SHOW = 1;
    const NOT_SHOW = 0;
    public static $showStatusList = [
        self::NOT_SHOW => '不显示',
        self::IS_SHOW => '显示',
    ];

    /**
     * status 状态
     */
    const ACTIVE_STATUS = 0;
    const DEL_STATUS = 1;
    public static $statusList = [
        self::ACTIVE_STATUS => '显示',
        self::DEL_STATUS => '回收站',
    ];

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%painting}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['category_id', 'status', 'show_banner', 'created_at', 'updated_at'], 'integer'],
            [['category_id', 'user_id', 'created_at', 'updated_at'], 'required', 'message' => '不能为空'],
            [['describe'], 'string'],
            [['image', 'thumb', 'title'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'category_id' => '分类',
            'user_id' => '作者',
            'image' => '作品',
            'thumb' => '缩略图',
            'title' => '标题',
            'describe' => '描述',
            'status' => '状态',
            'show_banner' => '是否banner展示',
            'created_at' => '创建时间',
            'updated_at' => '更新时间',
        ];
    }

    public function getCategory()
    {
        return $this->hasOne(Category::className(), ['id'=>'category_id']);
    }

    public function getAdmin()
    {
        return $this->hasOne(Admin::className(), ['id' => 'user_id']);
    }
}
